import { HttpMethod } from '@/services/types';
import { request } from '@/api/request';
/**
 * POST /auth/login 账号登录
 * @param params
 * @param options
 */
export async function resLogin(
  params: API.LoginParams,
  options?: { [key: string]: any },
) {
  return request<API.LoginResult>('/auth/login', {
    method: HttpMethod.POST,
    data: params,
    ...(options || {}),
  },false);
}

/**
 * POST /auth/login/phone 手机登录
 * @param params
 * @param options
 */
export async function resPhoneLogin(
  params: API.LoginPhoneParams,
  options?: { [key: string]: any },
) {
  return request<API.LoginResult>('/auth/login/phone', {
    method: HttpMethod.POST,
    data: params,
    ...(options || {}),
  },false)}

/**
 * POST /auth/code/phone 发送手机验证码
 * @param params
 * @param options
 */
export async function resSendSmsCode(
  params:API.PhoneCodeParams,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/auth/code/phone', {
    method: HttpMethod.POST,
    data: params,
    ...(options || {}),
  });
}

/**
 * POST /auth/register/phone 手机注册
 * @param params
 * @param options
 */
export async function resPhoneRegister(
  params: API.PhoneRegisterParams,
  options?: { [key: string]: any },
) {
  return request<string>('/auth/register/phone', {
    method: HttpMethod.POST,
    data: params,
    ...(options || {}),
  });
}

/**
 * POST /auth/code/email 发送邮箱验证码
 * @param params
 * @param options
 */
export async function resSendEmailCode(
  params: API.EmailCodeParams,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/auth/code/email', {
    method: HttpMethod.POST,
    data: params,
    ...(options || {}),
  });
}

/**
 * POST /auth/register/email 邮箱注册
 * @param params
 * @param options
 */
export async function resEmailRegister(
  params: API.EmailRegisterParams,
  options?: { [key: string]: any },
) {
  return request<R<string>>('/auth/register/email', {
    method: HttpMethod.POST,
    data: params,
    ...(options || {}),
  });
}

/**
 * GET /auth/captcha 获取图片验证码
 * @param options
 */
export async function resCaptcha(
  options?: { [key: string]: any },
) {
  return request<string>('/auth/captcha?time='+Date.now(), {
    method: HttpMethod.GET,
    ...(options || {}),
  });
}

/**
 * POST /auth/refresh_token 刷新token
 * @param options
 */
export async function resRefreshToken(
  options?: { [key: string]: any },
) {
  return request<API.LoginResult>('/auth/refresh_token', {
    method: HttpMethod.POST,
    ...(options || {}),
  });
}

/**
 * POST /auth/logout 注销登录
 * @param options
 */
export async function resLogout(
  options?: { [key: string]: any },
) {
  return request<API.LoginResult>('/auth/logout', {
    method: HttpMethod.POST,
    ...(options || {}),
  });
}

/**
 * PUT /auth/reset/password 重置密码
 * @param params
 * @param options
 */
export async function resResetPassword(
  params: API.ResetPasswordParams,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/auth/reset/password', {
    method: HttpMethod.PUT,
    data: params,
    ...(options || {}),
  });
}

/**
 * PUT /auth/password 更换密码
 * @param params
 * @param options
 */
export async function resChangePassword(
  params: API.ChangePasswordParams,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/auth/password', {
    method: HttpMethod.PUT,
    data: params,
    ...(options || {}),
  });
}

/**
 * PATCH /auth/phone 更换手机
 * @param params
 * @param options
 */
export async function resChangePhone(
  params: API.ChangePhoneParams,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/auth/phone', {
    method: HttpMethod.PATCH,
    data: params,
    ...(options || {}),
  });
}


/**
 * PATCH /auth/email 更换邮箱
 * @param params
 * @param options
 */
export async function resChangeEmail(
  params: API.ChangeEmailParams,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/auth/email', {
    method: HttpMethod.PATCH,
    data: params,
    ...(options || {}),
  });
}